/*******************************************************************************
 * Copyright 2011, 2012 Chris Banes.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.byCreation.t_globe;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import com.byCreation.Control.HackyViewPager;
import com.byCreation.t_globe.R;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.squareup.picasso.Picasso;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.ImageView;

import uk.co.senab.photoview.PhotoView;


public class ViewPagerPhotoViewActivity extends Activity {

	
	

	
	
	
	
	
    @Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_view_pager);
        ViewPager mViewPager = (HackyViewPager) findViewById(R.id.view_pager);
		setContentView(mViewPager);
		//mViewPager.
		

		//mViewPager.requestDisallowInterceptTouchEvent(false);
		mViewPager.setAdapter(new SamplePagerAdapter(ViewPagerPhotoViewActivity.this));
		mViewPager.setCurrentItem(PhotoActivity.index_photo);
	}

    private LayoutInflater inflater;
	 class SamplePagerAdapter extends PagerAdapter {

		 private Activity _activity;
		
		 
		 
		 public SamplePagerAdapter(Activity activity) {
		        this._activity = activity;
		      
		    }
		 
		 
		@Override
		public int getCount() {
			return CardDetailActivity.MyArrList_gallery.size();
		}
		
		
		@Override
		public View instantiateItem(ViewGroup container, int position) {
			
			inflater = (LayoutInflater) _activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        View view = inflater.inflate(R.layout.item_photoview, container,false);
			
	        
	        PhotoView iv_photo=(PhotoView)view.findViewById(R.id.iv_photo);
	        Picasso.with(ViewPagerPhotoViewActivity.this).load(CardDetailActivity.MyArrList_gallery.get(position).get("img").toString()).into(iv_photo);	
	        
	        Log.e("TG", "MyArrList_gallery[position]:"+CardDetailActivity.MyArrList_gallery.get(position).get("img").toString());
	        
//			PhotoView photoView = new PhotoView(container.getContext());
//		
//	 		try {
//		         Picasso.with(ViewPagerPhotoViewActivity.this).load(PhotoActivity.IMAGES[position]).into(photoView);	
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//			Log.e("PhotoView","position="+position);
	      
	        ((ViewPager) container).addView(view);

			
			
			
			
			return view;
		}

		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			container.removeView((View) object);
		}

		@Override
		public boolean isViewFromObject(View view, Object object) {
			return view == object;
		}

	}
	
	
	
	
	

}
